package hander

import (
	"api-client/api/request"
	__ "api-client/proto"
	"github.com/gin-gonic/gin"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"log"
	"net/http"
)

func Login(c *gin.Context) {
	var req request.Login

	conn, err := grpc.NewClient("127.0.0.1:8803", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	defer conn.Close()

	client := __.NewUserClient(conn)

	client.Login(c, &__.LoginReq{
		Mobile:      req.Mobile,
		SendSmsCode: req.SendSmsCode,
	})

	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "登录成功",
		"data": nil,
	})

}

func Create(c *gin.Context) {
	var req request.List

	//if err := c.ShouldBind(&req); err != nil {
	//	c.JSON(http.StatusBadGateway, gin.H{
	//		"code": 500,
	//		"msg":  "参数解析失败",
	//		"data": nil,
	//	})
	//}

	conn, err := grpc.NewClient("127.0.0.1:8803", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	defer conn.Close()

	client := __.NewUserClient(conn)

	client.List(c, &__.ListReq{
		Id: int64(req.Id),
	})

	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "展示成功",
	})
}
